Skip to content

fix: correctly output packages from osv-scanner.json source in spdx format#2641

Open
Mananshah237 wants to merge 2 commits intogoogle:mainfrom
Mananshah237:main
Open

fix: correctly output packages from osv-scanner.json source in spdx format#2641
Mananshah237 wants to merge 2 commits intogoogle:mainfrom
Mananshah237:main

Conversation

@Mananshah237
Copy link
Copy Markdown

Fixes #2192

Packages loaded from an osv-scanner.json results file have Inventory == nil
because PackageInfo.Inventory is not populated during JSON deserialization.

PrintSPDXResults was blindly appending nil Inventory values, causing the
SPDX converter to silently skip all such packages.

This fix constructs a synthetic extractor.Package using the available
PackageInfo fields (name, version, ecosystem) when Inventory is nil.

Maven packages require special handling because their names are stored as
groupId:artifactId in osv-scanner. The scalibr PURL converter requires
javalockfile.Metadata with GroupID and ArtifactID to generate the correct
pkg:maven/groupId/artifactId@version PURL.

This ensures packages from osv-scanner.json sources appear correctly
in the generated SPDX SBOM output.

…format

Packages loaded from an osv-scanner.json results file have Inventory == nil
because PackageInfo.Inventory is not populated during JSON deserialization.
PrintSPDXResults was blindly appending nil Inventory values, causing the SPDX
converter to silently skip all such packages.

Fix by constructing a synthetic extractor.Package from available PackageInfo
fields (name, version, ecosystem) when Inventory is nil. Maven packages require
special handling to produce the correct pkg:maven PURL.

Fixes google#2192
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 12, 2026

Codecov Report

❌ Patch coverage is 68.96552% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.56%. Comparing base (276a0eb) to head (ea60545).
⚠️ Report is 55 commits behind head on main.

Files with missing lines Patch % Lines
internal/output/spdx.go 68.96% 6 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2641       +/-   ##
===========================================
+ Coverage   68.03%   79.56%   +11.53%     
===========================================
  Files         173      117       -56     
  Lines       13405     8042     -5363     
===========================================
- Hits         9120     6399     -2721     
+ Misses       3577     1263     -2314     
+ Partials      708      380      -328     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Collaborator

@another-rex another-rex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, pretty neat fix!

Just need to fix the linting issues and one comment, otherwise LGTM.

Comment thread internal/output/spdx.go Outdated

// inventoryFromPackageInfo constructs a synthetic extractor.Package from a PackageInfo
// for packages that don't have a populated Inventory field (e.g., loaded from osv-scanner.json).
func inventoryFromPackageInfo(pkg models.PackageInfo) *extractor.Package {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have this function return an error as well, rather than just nil, to be handled in the caller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scanning osv-scanner.json format does not correctly output spdx

3 participants